import string
with open("walden",'r+') as f:
    words = [word1.strip(string.punctuation).lower() for word1 in f.read().split()]
    words2 = set(words)
    dict= {i:words.count(i) for i in words2}
    #打印整理后的参数，其中利用lambda表达式，以字典中的值为排序的参数
    for word in sorted(dict,key=lambda x: dict[x],reverse=True):
        print('{} -- {} 次'.format(word,dict[word]))